]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/network: Add section classes for each device type
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 3 Aug 2022 03:27:44 +0000 (05:27 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 7 Aug 2022 20:41:09 +0000 (22:41 +0200)
Those will eventually become quick toggles, and as there'll be small
differences like menu headers or which settings panel to launch, it
makes sense to give each its own class.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2406>

js/ui/status/network.js

index 71c16d748d915e4c5cb851b3a4d6bb0977044683..7a436ba7a568b3867f2eeb3cad04c1e0289a1edc 100644 (file)
@@ -1541,41 +1541,82 @@ var NMDeviceSection = class extends PopupMenu.PopupMenuSection {
     }
 
     _getSummaryIcon() {
-        switch (this._deviceType) {
-        case NM.DeviceType.ETHERNET:
-            return 'network-wired-symbolic';
-        case NM.DeviceType.WIFI:
-        case NM.DeviceType.BT:
-        case NM.DeviceType.MODEM:
-            return 'network-wireless-symbolic';
-        }
-        return '';
+        throw new GObject.NotImplementedError();
     }
 
-    _getSummaryLabel(nDevices) {
-        switch (this._deviceType) {
-        case NM.DeviceType.ETHERNET:
-            return ngettext("%s Wired Connection",
-                            "%s Wired Connections",
-                            nDevices).format(nDevices);
-        case NM.DeviceType.WIFI:
-            return ngettext("%s Wi-Fi Connection",
-                            "%s Wi-Fi Connections",
-                            nDevices).format(nDevices);
-        case NM.DeviceType.BT:
-            return ngettext(
-                '%s Bluetooth Connection',
-                '%s Bluetooth Connections',
-                nDevices).format(nDevices);
-        case NM.DeviceType.MODEM:
-            return ngettext("%s Modem Connection",
-                            "%s Modem Connections",
-                            nDevices).format(nDevices);
-        }
-        return '';
+    _getSummaryLabel() {
+        throw new GObject.NotImplementedError();
     }
 };
 
+class NMWirelessSection extends NMDeviceSection {
+    constructor() {
+        super(NM.DeviceType.WIFI);
+    }
+
+    _getSummaryIcon() {
+        return 'network-wireless-symbolic';
+    }
+
+    _getSummaryLabel(nDevices) {
+        return ngettext(
+            '%s Wi-Fi Connection',
+            '%s Wi-Fi Connections',
+            nDevices).format(nDevices);
+    }
+}
+
+class NMWiredSection extends NMDeviceSection {
+    constructor() {
+        super(NM.DeviceType.ETHERNET);
+    }
+
+    _getSummaryIcon() {
+        return 'network-wired-symbolic';
+    }
+
+    _getSummaryLabel(nDevices) {
+        return ngettext(
+            '%s Wired Connection',
+            '%s Wired Connections',
+            nDevices).format(nDevices);
+    }
+}
+
+class NMBluetoothSection extends NMDeviceSection {
+    constructor() {
+        super(NM.DeviceType.BT);
+    }
+
+    _getSummaryIcon() {
+        return 'network-wireless-symbolic';
+    }
+
+    _getSummaryLabel(nDevices) {
+        return ngettext(
+            '%s Bluetooth Connection',
+            '%s Bluetooth Connections',
+            nDevices).format(nDevices);
+    }
+}
+
+class NMModemSection extends NMDeviceSection {
+    constructor() {
+        super(NM.DeviceType.MODEM);
+    }
+
+    _getSummaryIcon() {
+        return 'network-wireless-symbolic';
+    }
+
+    _getSummaryLabel(nDevices) {
+        return ngettext(
+            '%s Modem Connection',
+            '%s Modem Connections',
+            nDevices).format(nDevices);
+    }
+}
+
 var NMApplet = GObject.registerClass(
 class Indicator extends PanelMenu.SystemIndicator {
     _init() {
@@ -1616,18 +1657,20 @@ class Indicator extends PanelMenu.SystemIndicator {
         this._notification = null;
 
         this._nmDevices = [];
-        this._deviceSections = new Map();
-
-        const sections = [
-            [NMConnectionCategory.WIRED, NM.DeviceType.ETHERNET],
-            [NMConnectionCategory.WIRELESS, NM.DeviceType.WIFI],
-            [NMConnectionCategory.BLUETOOTH, NM.DeviceType.BT],
-            [NMConnectionCategory.WWAN, NM.DeviceType.MODEM],
-        ];
-        for (const [category, deviceType] of sections) {
-            this._deviceSections.set(category, new NMDeviceSection(deviceType));
-            this.menu.addMenuItem(this._deviceSections.get(category));
-        }
+
+        this._wiredSection = new NMWiredSection();
+        this._wirelessSection = new NMWirelessSection();
+        this._modemSection = new NMModemSection();
+        this._btSection = new NMBluetoothSection();
+
+        this._deviceSections = new Map([
+            [NMConnectionCategory.WIRED, this._wiredSection],
+            [NMConnectionCategory.WIRELESS, this._wirelessSection],
+            [NMConnectionCategory.WWAN, this._modemSection],
+            [NMConnectionCategory.BLUETOOTH, this._btSection],
+        ]);
+        for (const section of this._deviceSections.values())
+            this.menu.addMenuItem(section);
 
         this._vpnSection = new NMVpnSection(this._client);
         this._vpnSection.connect('activation-failed', this._onActivationFailed.bind(this));